import QtQuick
// import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts

ApplicationWindow {
    width: rootWidth
    height: rootHeight
    visible: true

    // visibility:"Windowed"   // 全屏显示应用程序
    visibility:"FullScreen"   // 全屏显示应用程序

    //显示到副屏
    x: Qt.application.screens[1].virtualX
    y: Qt.application.screens[1].virtualY

    property real rootWidth: Screen.width
    property real rootHeight: Screen.height

    // property real rootWidth: 1080
    // property real rootHeight: 1920

    // 管理密码 标志位
    property bool managerKey_Flag: false

    property string warningShowText

    function warningSignalChanged(warningDetail)
    {
        // console.log("warningDetail:" + warningDetail)

        if(warningDetail === warningShowText)
        {
            return;
        }

        if("当前报警:" === warningDetail)
        {
            warningShowText = warningDetail
            warningAreaBack.visible = false
            warningText.visible = false
            sequentialAnimation.stop()
        }
        else if("Cảnh báo hiện tại:"=== warningDetail)
        {
            warningAreaBack.visible = false
            warningText.visible = false
            sequentialAnimation.stop()
        }
        else
        {
            warningShowText = warningDetail
            warningAreaBack.visible = true
            warningText.visible = true
            sequentialAnimation.restart()
        }
    }


    Component.onCompleted: {
        // 加载手动加工界面
        contentLoader.source = "ManualProcessWindow.qml"
        Cpp_PLC.warning_Signal_Changed_Sig.connect(warningSignalChanged);
        sequentialAnimation.start()
    }

    property bool warning_Jerk_Flag :Cpp_PLC.Warning_Jerk
    property bool warning_Servo_Flag : Cpp_PLC.Warning_Servo
    property bool warning_Front_Soft_Limit_Over_Flag : Cpp_PLC.Warning_Front_Soft_Limit_Over
    property bool warning_Back_Soft_Limit_Over_Flag : Cpp_PLC.Warning_Back_Soft_Limit_Over

    // 提示消息
    property bool m_42 : Cpp_PLC.M_42
    property bool m_43 : Cpp_PLC.M_43
    property bool m_47 : Cpp_PLC.M_47
    property bool m_52 : Cpp_PLC.M_52
    property bool m_56 : Cpp_PLC.M_56
    property bool m_57 : Cpp_PLC.M_57
    property bool m_58 : Cpp_PLC.M_58
    property bool m_59 : Cpp_PLC.M_59
    property bool m_64 : Cpp_PLC.M_64
    property bool m_68 : Cpp_PLC.M_68
    property bool m_69 : Cpp_PLC.M_69
    property bool m_73 : Cpp_PLC.M_73
    property bool m_76 : Cpp_PLC.M_76
    property bool m_77 : Cpp_PLC.M_77
    property bool m_80 : Cpp_PLC.M_80
    property bool m_134 : Cpp_PLC.M_134
    property bool m_137 : Cpp_PLC.M_137
    property bool m_143 : Cpp_PLC.M_143
    property bool m_149 : Cpp_PLC.M_149
    property bool m_152 : Cpp_PLC.M_152
    property bool m_153 : Cpp_PLC.M_153
    property bool m_159 : Cpp_PLC.M_159
    property bool m_164 : Cpp_PLC.M_164
    property bool m_170 : Cpp_PLC.M_170
    property bool m_196 : Cpp_PLC.M_196
    property bool m_197 : Cpp_PLC.M_197
    property bool m_250 : Cpp_PLC.M_250
    property bool m_251 : Cpp_PLC.M_251
    property bool m_252 : Cpp_PLC.M_252



    property var processPages: [
        { "title": qsTr("手动加工"), "source": "ManualProcessWindow.qml" },
        { "title": qsTr("超长加工"), "source": "ExtraLong_Process.qml" },
        { "title": qsTr("超短加工"), "source": "ExtraShort_Process.qml" },
        { "title": qsTr("角码加工"), "source": "Corner_Process.qml" }
    ]

    property var listPages: [
        { "title": qsTr("本地料单"), "source": "Order_Process.qml" },
        { "title": qsTr("二维码料单"), "source": "QRCode_Process.qml" },
        { "title": qsTr("网络料单"), "source": "NetWork_Process.qml" },
        { "title": qsTr("U盘料单"), "source": "USB_Process_Window.qml" }
    ]

    property var managePages: [
        {"title": qsTr("管理界面"), "source": "Manager_And_Setting_Process.qml"},
        {"title": qsTr("IO 监控"), "source": "IO_Monitor_Window.qml"}
    ]

    property var paramaterPages: [
        {"title": qsTr("打印机设定"), "source": "PrinterSettingWindow.qml"},
        {"title": qsTr("连接参数"), "source": "ConnectSettingWindow.qml"},
        {"title": qsTr("设备参数"), "source": "MechineParameterWindow.qml"},
        {"title": qsTr("伺服参数"), "source": "ServoSettingWindow.qml"},
        {"title": qsTr("拖料架参数"), "source": "HoldSettingWindow.qml"},
        {"title": qsTr("位置补偿"), "source": "LocationSettingWindow.qml"},
        {"title": qsTr("任意位置补偿"), "source": "AnyLocationSettingWindow.qml"}
    ]

    Item{
        id: root
        anchors.fill: parent
        Rectangle{
            anchors.fill: parent
            gradient: Gradient {
                orientation: Gradient.Vertical
                GradientStop { position: 0.0 ; color: "#FFFFFF"}
                GradientStop { position: 0.5 ; color: "#1E90FF"}
                GradientStop { position: 1.0 ; color: "#FFFFFF"}
            }
        }

    }

    MenuBar {
        // 视图菜单
        width: parent.width
        background: Rectangle{
            gradient:  defaultColor

            property var defaultColor : Gradient {
                orientation: Gradient.Vertical
                GradientStop { position: 0.0 ; color: "#FFFFFF"}
                GradientStop { position: 0.5 ; color: "#1E90FF"}
                GradientStop { position: 1.0 ; color: "#FFFFFF"}
            }                    

            A_Label{
                anchors.right: parent.right
                anchors.rightMargin: 160
                anchors.verticalCenter: parent.verticalCenter
                labelWidth: 150
                labelHeight: 44
                labelBack: "transparent"
                labelBorderColor: "transparent"
                label_pointSize: Cpp_Config.Language_Type === 1 ? 20 :  Cpp_Config.Language_Type === 2 ? 10 : 10
                label_Data: qsTr("当前位置:")
            }

            A_Label{
                anchors.right: parent.right
                anchors.rightMargin: 10
                anchors.verticalCenter: parent.verticalCenter
                labelWidth: 150
                labelHeight: 44
                labelBack: "transparent"
                labelBorderColor: "transparent"
                label_pointSize: 20
                label_Data: Cpp_PLC.CurrentLocationValue

            }

        }

        Menu {
            title: qsTr("加工模式")            

            // 动态生成菜单项
            Repeater {
                // id: repeater
                model: processPages
                delegate: MenuItem {
                    text: modelData.title

                    onTriggered: {
                        contentLoader.source = modelData.source                        
                    }

                    // 添加分隔线（最后一个不显示）
                    MenuSeparator {
                        visible: index !== processPages.length-1
                        height: 10
                    }
                }
            }
        }

        Menu {
            title: qsTr("料单选择")
            font.bold: true
            // 动态生成菜单项
            Repeater {
                // id: repeater
                model: listPages
                delegate: MenuItem {
                    text: modelData.title

                    onTriggered: {
                        contentLoader.source = modelData.source
                    }

                    // 添加分隔线（最后一个不显示）
                    MenuSeparator {
                        visible: index !== listPages.length-1
                        height: 10
                    }
                }
            }
        }

        Menu {
            title: qsTr("设备调试")
            font.bold: true
            // 动态生成菜单项
            Repeater {
                // id: repeater
                model: managePages
                delegate: MenuItem {
                    text: modelData.title

                    onTriggered: {
                        contentLoader.source = modelData.source
                    }

                    // 添加分隔线（最后一个不显示）
                    MenuSeparator {
                        visible: index !== managePages.length-1
                        height: 10
                    }
                }
            }
        }

        Menu {
            title: qsTr("参数设置")
            font.bold: true
            // 动态生成菜单项
            Repeater {
                // id: repeater
                model: paramaterPages
                delegate: MenuItem {
                    text: modelData.title

                    onTriggered: {
                        if(index > 2 && managerKey_Flag === false)
                        {
                            // console.log("触发管理弹窗")

                            managerDialog.open()

                        }
                        else
                        {
                            contentLoader.source = modelData.source
                        }

                    }

                    // 添加分隔线（最后一个不显示）
                    MenuSeparator {
                        visible: index !== paramaterPages.length-1
                        height: 10
                    }
                }
            }
        }

        // 系统菜单（示例）
        Menu {
            title: qsTr("系统")
            font.bold: true

            MenuItem {
                text: qsTr("加密界面")
                onTriggered:  {
                    if(managerKey_Flag === false)
                    {
                        managerDialog.open()
                    }
                    else
                    {
                        contentLoader.source = "PasswordSettingWindow.qml"
                    }

                }
            }
            MenuItem {
                text: qsTr("配置")
                // visible: false
                // onTriggered: contentLoader.source = "ConfigDeviceWindow.qml"
                onTriggered:  {
                    if(managerKey_Flag === false)
                    {
                        managerDialog.open()
                    }
                    else
                    {
                        contentLoader.source = "ConfigDeviceWindow.qml"
                    }

                }
            }
            MenuItem {
                text: qsTr("退出")
                onTriggered: powerOffDialog.open()
            }
        }
    }

    A_Dialog{
        id: powerOffDialog
        onAccepted: Qt.quit()
        onRejected: powerOffDialog.close()
        title: qsTr("退出程序")
        dialog_FontColor: "red"
        dialog_FontData: qsTr("您要退出程序吗?" + "\n" + "点击确定")
    }    


    // 页面加载容器
    Loader {
        id: contentLoader
        anchors.top: root.top
        anchors.topMargin: 44

        // 加载状态处理
        onStatusChanged: {
            switch(status) {
            case Loader.Null:
                console.debug("Loader is empty")
                break
            case Loader.Ready:
                console.info("Page loaded:", source)
                break
            case Loader.Loading:
                console.debug("Loading:", source)
                break
            case Loader.Error:
                console.error("Load failed:", source)
                break
            }
        }

    }


    // 管理密码输入弹窗
    A_Dialog{
        id: managerDialog
        onRejected: managerDialog.close()
        title: qsTr("请输入管理密码")
        // dialog_FontColor: "black"
        dialog_FontData:""

        A_NumberKeyboard{
            id: passwdKeyboard
        }

        A_NumberInput{
            anchors.centerIn: parent
            inputWidth: 300
            fontPixelSize : 30
            isPassword: true
            // isSelected: true
            keyboard: passwdKeyboard

            onEditingFinished: function(value)
            {
                if(value === "2222")
                {
                    managerKey_Flag = true
                }
                else
                {
                    return;
                }
            }

        }

        // Rectangle{
        //     anchors.centerIn: parent
        //     width: 300
        //     height: 80
        //     border.width: 1
        //     radius: 10

        //     TextInput{
        //         id: managerKeyInput
        //         // width: 300
        //         // height: 80
        //         anchors.centerIn: parent
        //         font.pixelSize: 40
        //         font.bold: true
        //         maximumLength: 6
        //         echoMode: TextInput.Password

        //         onEditingFinished: {
        //             managerKeyInput.focus = false
        //         }

        //     }

        //     MouseArea{
        //         anchors.fill: parent

        //         onClicked: {
        //             managerKeyInput.forceActiveFocus()
        //         }
        //     }
        // }



        // onAccepted: {
        //     if(managerKeyInput.text === "2222")
        //     {
        //         managerKey_Flag = true
        //     }
        //     else
        //     {
        //         return;
        //     }
        // }


    }


    ////////////////////////报警信息/////////////////////////

    Rectangle{
        id: warningAreaBack
        anchors.horizontalCenter: root.horizontalCenter
        anchors.bottom: root.bottom
        width: 1080
        height: 90
        color: "gold"


        Text{
            id: warningText
            width : parent.width
            height : parent.height
            // y:10
            // anchors.verticalCenter: parent.verticalCenter
            horizontalAlignment: Text.AlignLeft
            font.pixelSize: 70
            font.bold: true
            color: "red"
            text: warningShowText
        }

        SequentialAnimation {
            id: sequentialAnimation
            loops: Animation.Infinite // 无限循环
            running: true

            // 从当前位置移动到 -width 的位置
            NumberAnimation {
                target: warningText
                properties: "x"
                from: warningText.width;
                to: -warningText.contentWidth
                duration: 5000 // 持续时间5000毫秒
                easing.type: Easing.Linear // 线性插值
            }

            // 瞬间跳回原点
            NumberAnimation {
                target: warningText
                properties: "x"
                to: 0
                duration: 0 // 瞬间完成
            }
        }

    }






    ////////////////////////提示弹窗部分////////////////////////////////

    Popup{      // M42  X轴正限位有效 禁止左行
        id: popup_01
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_42
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_01_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("X轴负限位有效，禁止电机左行!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_01_root.horizontalCenter
            anchors.bottom: popup_01_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(42,"0")
            }
        }

    }
    Popup{      // M43  X轴正限位有效 禁止右行
        id: popup_02
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_43
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_02_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("X轴正限位有效，禁止电机右行!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_02_root.horizontalCenter
            anchors.bottom: popup_02_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(43,"0")
            }
        }

    }
    Popup{      // M47  当前位置 = 定位位置
        id: popup_03
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_47
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_03_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("当前位置 = 定位位置!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_03_root.horizontalCenter
            anchors.bottom: popup_03_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(47,"0")
            }
        }

    }
    Popup{      // M52  位置清零失败
        id: popup_04
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_52
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_04_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("位置清零失败!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_04_root.horizontalCenter
            anchors.bottom: popup_04_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(52,"0")
            }
        }

    }
    Popup{      // M56  伺服未准备好
        id: popup_05
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_56
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_05_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("伺服未准备好!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_05_root.horizontalCenter
            anchors.bottom: popup_05_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(56,"0")
            }
        }

    }
    Popup{      // M57  读取位置失败
        id: popup_06
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_57
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_06_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("读取位置失败!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_06_root.horizontalCenter
            anchors.bottom: popup_06_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(57,"0")
            }
        }

    }
    Popup{      // M58  读取位置成功
        id: popup_07
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_58
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_07_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("读取位置成功!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_07_root.horizontalCenter
            anchors.bottom: popup_07_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(58,"0")
            }
        }

    }
    Popup{      // M59  设备原点未建立，禁止电机运行
        id: popup_08
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_59
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_08_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("设备零点未建立，禁止电机运行!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_08_root.horizontalCenter
            anchors.bottom: popup_08_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(59,"0")
            }
        }

    }
    Popup{      // M64  左右机头未选择
        id: popup_09
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_64
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_09_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("左右机头未选择!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_09_root.horizontalCenter
            anchors.bottom: popup_09_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(64,"0")
            }
        }

    }
    Popup{      // M68  锯片工进中，禁止压料
        id: popup_10
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_68
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_10_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("锯片工进中禁止压料动作!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_10_root.horizontalCenter
            anchors.bottom: popup_10_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(68,"0")
            }
        }

    }
    Popup{      // M69  锯片后位信号异常，禁止压料
        id: popup_11
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_69
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_11_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("锯片后位信号异常，禁止压料动作!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_11_root.horizontalCenter
            anchors.bottom: popup_11_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(69,"0")
            }
        }

    }
    Popup{      // M73  当前段数已加工完
        id: popup_12
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_73
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_12_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("当前段数已加工完成!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_12_root.horizontalCenter
            anchors.bottom: popup_12_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(73,"0")
            }
        }

    }
    Popup{      // M76  锯片未启动，禁止锯片出锯
        id: popup_13
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_76
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_13_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("锯片电机未启动，禁止出锯!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_13_root.horizontalCenter
            anchors.bottom: popup_13_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(76,"0")
            }
        }

    }
    Popup{      // M77  压料气缸未压紧，禁止锯片出锯
        id: popup_14
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_77
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_14_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("压料气缸未压紧，禁止出锯!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_14_root.horizontalCenter
            anchors.bottom: popup_14_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(77,"0")
            }
        }

    }
    Popup{      // M80  当前位置≠定位位置，禁止锯片出锯
        id: popup_15
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_80
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_15_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("当前位置≠定位位置，禁止锯片出锯!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_15_root.horizontalCenter
            anchors.bottom: popup_15_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(80,"0")
            }
        }

    }
    Popup{      // M134  料长设定错误
        id: popup_16
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_134
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_16_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("料长设定错误!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_16_root.horizontalCenter
            anchors.bottom: popup_16_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(134,"0")
            }
        }

    }
    Popup{      // M137  锯片到位信号异常
        id: popup_17
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_137
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_17_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("锯片到位信号异常!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_17_root.horizontalCenter
            anchors.bottom: popup_17_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(137,"0")
            }
        }

    }
    Popup{      // M143  超短模式请先复位
        id: popup_18
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_143
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_18_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("超短模式请先复位!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_18_root.horizontalCenter
            anchors.bottom: popup_18_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(143,"0")
            }
        }

    }
    Popup{      // M149  请先按下定位按钮，进行定位
        id: popup_19
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_149
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_19_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("请先按下定位按钮，进行定位!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_19_root.horizontalCenter
            anchors.bottom: popup_19_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(149,"0")
            }
        }

    }
    Popup{      // M152  当前坐标已清零
        id: popup_20
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_152
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_20_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("当前坐标已清零!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_20_root.horizontalCenter
            anchors.bottom: popup_20_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(152,"0")
            }
        }

    }
    Popup{      // M153  当前位置禁止内摆
        id: popup_21
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_153
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_21_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("当前位置禁止内摆!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_21_root.horizontalCenter
            anchors.bottom: popup_21_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(153,"0")
            }
        }

    }
    Popup{      // M159  当前位置≠定位位置，禁止锯片出锯
        id: popup_22
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_159
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_22_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("压料气缸压紧中，禁止移动!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_22_root.horizontalCenter
            anchors.bottom: popup_22_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(159,"0")
            }
        }

    }
    Popup{      // M164  当前左右选择模式未旋钮，请切换为触控选择
        id: popup_23
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_164
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_23_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("当前左右锯选择模式为旋钮"+"\n"+"  请切换为触控选择!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_23_root.horizontalCenter
            anchors.bottom: popup_23_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(164,"0")
            }
        }

    }
    Popup{      // M170  误差修正完成
        id: popup_24
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_170
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_24_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("误差修正完成!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_24_root.horizontalCenter
            anchors.bottom: popup_24_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(170,"0")
            }
        }

    }
    Popup{      // M196  清除电池报警失败
            id: popup_25
            parent: root
            anchors.centerIn: root
            width: 900
            height: 900
            visible: m_196
            closePolicy : Popup.NoAutoClose
            modal:  true

            background: Rectangle{
                color: "gold"
            }

            Item{
                id: popup_25_root
                anchors.fill: parent

            }
            Text{
                anchors.centerIn: parent
                font.pixelSize: 50
                font.bold: true
                color: "red"
                text: qsTr("清除电池报警失败!!!")
            }

            A_Button{
                anchors.horizontalCenter: popup_25_root.horizontalCenter
                anchors.bottom: popup_25_root.bottom
                contentText_Data: qsTr("关 闭")
                onButtonClicked: {
                    Cpp_PLC.write_Modbus_RTU_Coils(196,"0")
                }
            }

        }
    Popup{      // M197  报警已清除，请重启
        id: popup_26
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_197
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_26_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("报警已清除，请重启程序!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_26_root.horizontalCenter
            anchors.bottom: popup_26_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(197,"0")
            }
        }

    }
    Popup{      // M250  前托退到位异常
        id: popup_27
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_250
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_27_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("前托退到位信号异常!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_27_root.horizontalCenter
            anchors.bottom: popup_27_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(250,"0")
            }
        }

    }
    Popup{      // M251  中托退到位异常
        id: popup_28
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_251
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_28_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("中托退到位信号异常!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_28_root.horizontalCenter
            anchors.bottom: popup_28_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(251,"0")
            }
        }

    }
    Popup{      // M252  后托退到位异常
        id: popup_29
        parent: root
        anchors.centerIn: root
        width: 900
        height: 900
        visible: m_252
        closePolicy : Popup.NoAutoClose
        modal:  true

        background: Rectangle{
            color: "gold"
        }

        Item{
            id: popup_29_root
            anchors.fill: parent

        }
        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text: qsTr("后托退到位信号异常!!!")
        }

        A_Button{
            anchors.horizontalCenter: popup_29_root.horizontalCenter
            anchors.bottom: popup_29_root.bottom
            contentText_Data: qsTr("关 闭")
            onButtonClicked: {
                Cpp_PLC.write_Modbus_RTU_Coils(252,"0")
            }
        }

    }



    Rectangle{
        // visible: Cpp_PLC.LockMechine_Flag
        visible: false
        color: "gold"
        anchors.fill: root

        Text{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 300
            font.pixelSize: 100
            font.bold: true
            color: "red"
            text: qsTr("设备已锁定!!!")
        }
        Text{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 500
            font.pixelSize: Cpp_Config.Language_Type === 1 ? 100 :  Cpp_Config.Language_Type === 1 ? 70 : 70
            font.bold: true
            color: "red"
            text: qsTr("请联系厂商进行解锁!")
        }


        // RowLayout{
        //     anchors.top: parent.top
        //     anchors.topMargin: 1200
        //     anchors.horizontalCenter: parent.horizontalCenter
        //     spacing: 20

        //     A_Label{
        //         labelWidth: 100
        //         label_pointSize: 30
        //         label_Data: qsTr("密 码")
        //     }

        //     A_TextInput{
        //         id: passwdInput
        //         inputWidth: 600
        //         maxDataLength: 20
        //         validatorFlag: false
        //         showData: inputData

        //         MouseArea{
        //             anchors.fill: parent

        //             onDoubleClicked: {
        //                 passwdInput.childAt()
        //             }
        //         }

        //     }

        //     A_Button{
        //         contentText_Data: "解 密"
        //         contentText_Fontsize: 40

        //         onButtonClicked: {
        //             Cpp_Config.getPassWord(passwdInput.inputData)
        //         }
        //     }
        // }

    }




}
